package com.example.demo.test;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class test05

{
    private static Map<String,Object> analysisDayLimit (String msg){
        Map<String,Object> map = new HashMap<>();

        List<String> list = new ArrayList<>();
        StringBuilder errorMsg = new StringBuilder();


        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(msg);
        while (matcher.find()) {
            list.add(matcher.group(0));
        }
        if(list.size() == 2 && Integer.valueOf(list.get(0)).compareTo(Integer.valueOf(list.get(1))) < 0){
            map.put("deliveryDayMin",list.get(0));
            map.put("deliveryDayMax",list.get(1));
        }else {
            errorMsg.append("送达时效的时间范围不正确");
        }
        if(StringUtils.contains(msg, "工作日")){
            map.put("timeType", 1);
        }else if(StringUtils.contains(msg, "自然日")){
            map.put("timeType", 0);
        }else{
            errorMsg.append("送达时效的单位应为工作日或自然日");
        }
        map.put("errorMsg",errorMsg);
        return map;
    }

    // 取括号内的数字
    private static List<String> getNumber(String msg) {


        //    String msg = "公式一:长CM + (宽CM + 高CM) * 2 ≥ ( 10 ) CM";
        List<String> list = new ArrayList<String>();
        Matcher m = Pattern.compile("\\((.*?)\\)").matcher(msg);
        while (m.find()) {
            String item = m.group(0).substring(1, m.group().length() - 1).trim();
            if (item.matches("[0-9]+")) {
                list.add(item);
            }
        }
        return list;
    }

    private static List<String> getNumber(){
        String day = DateFormatUtils.format(System.currentTimeMillis(),"yy-MM-dd HH-mm-ss");
        String msg = "公式一:长CM + (宽CM + 高CM) * 2 ≥ ( 1 0 ) CM";
        List<String> list = new ArrayList<String>();
        Matcher m = Pattern.compile("\\((.*?)\\)").matcher(msg);
        while (m.find()) {
            String item = m.group(0).substring(1, m.group().length() - 1).trim();
            if(item.matches("[0-9]+")){
                list.add(item);
            }

        }
        return list;

    }
    private static String getPropertyTransaction(String productProperty) {
        String content = "胆小重量不超过78KG989dd打34kg*2大于100, ";
        List<String> list = new ArrayList<>();
        String template = "胆小重量不超过%sKG%sdd打%skg*2大于100";


        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            list.add(matcher.group(0));
        }
        for (String s : list) {
            content.replace(s, "%s");
        }
        return "";
    }

    public static void compareDate(){
        String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
        if(today.compareTo("20200630")>0){
            System.out.println(today+"在20200630之前");
        }
    }

    public static void method1 (){
        try {
            System.out.println(URLEncoder.encode("导入头程渠道模板.xlsx", "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(date);
        System.out.println(time);


        Boolean flag = "sss".equals(null);
//        analysisDayLimit ("13-121作日");
//        getNumber("ss");
//        method1();
//        compareDate();
//        String property = "non_liquid_cosmetics,with_magnetic,liquid,powder,special_sensitive_goods";
//        String property = "";
//        getPropertyTransaction(property);

        String publishTime = "2021-07-08T16:00:00.000Z";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date intervalPublishTime = null;
        try {
            intervalPublishTime = format.parse("2017-08-02");
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
